Ext.onReady(function () {
    //初始化标签中的Ext:Qtip属性。
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'side';
    //创建div组件
    // var imagebox = new Ext.BoxComponent({
    //     autoEl: {
    //         style: 'width:150px;height:150px;margin:0px auto;border:1px solid #ccc; text-align:center;padding-top:20px;margin-bottom:10px',
    //         tag: 'div',
    //         id: 'imageshow',
    //         html: '暂无图片'
    //     }
    // });
    //创建文本上传域
    var file = new Ext.form.TextField({
        name: 'imgFile',
        fieldLabel: '文件上传',
        inputType: 'file',
        allowBlank: false,
        blankText: '请浏览图片'
    });
    //提交按钮处理方法
    var btnsubmitclick = function () {
        if (form.getForm().isValid()) {
            form.getForm().submit({
                waitTitle: "请稍候",
                waitMsg: '正在上传...',
                success: function (form, action) {
                    Ext.MessageBox.alert("提示", "上传成功！");
                    // document.getElementById('imageshow').innerHTML = '<img style="width:150px; height:150px" src="' + action.result.path + '"/>';
                },
                failure: function () {
                    Ext.MessageBox.alert("提示", "上传失败！");
                }
            });
        }
    };
    //重置按钮"点击时"处理方法
    var btnresetclick = function () {
        form.getForm().reset();
    };
    //表单
    var form = new Ext.form.FormPanel({
        frame: true,
        fileUpload: true,
        url: 'upload.do',
        method : 'POST',
        title: '上传文件',
        style: 'margin:10px',
        // items: [imagebox, file],
        items: [file],
        buttons: [{
            text: '上传',
            handler: btnsubmitclick
            }, {
            text: '取消',
            handler: btnresetclick
        }]
    });
    //窗体
    var win = new Ext.Window({
        title: '选择文件',
        width: 476,
        height: 200,
        resizable: false,
        modal: true,
        closable: false,
        maximizable: false,
        minimizable: false,
        buttonAlign: 'center',
        items: form
    });
    win.show();
});